<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/inc/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新建文章</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${path}/static/css/public.css" media="all"/>
</head>
<style>
    .layui-input {
        width: 300px;
    }

    .layui-row{
        margin-top: 1%;
    }
</style>
<body class="childrenBody">
<form class="layui-form">
    <input type="hidden" name="id" value="${wenzhang.id}">
    <div class="layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label"><span style="color: red">*</span>文章标题</label>
            <div class="layui-input-block">
                <input type="text" name="wzName" lay-verify="required" autocomplete="off" placeholder="请输入文章标题"
                       class="layui-input" value="${wenzhang.wzName}">
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label"><span style="color: red">*</span>文章类别</label>
            <div class="layui-input-inline">
                <select name="lId" id="lId" lay-verify="required" lay-filter="articleGroup">
                    <option value="">请选择</option>
                    <c:forEach items="${groupList}" var="table">
                        <c:if test="${wenzhang.lId == table.id}">
                            <option value="${table.id}" selected="selected">${table.lxName}</option>
                        </c:if>
                        <c:if test="${wenzhang.lId != table.id}">
                            <option value="${table.id}">${table.lxName}</option>
                        </c:if>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文章内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="detail" class="layui-textarea">${wenzhang.detail}</textarea>
            </div>
        </div>
    </div>
    <!-- 按钮 -->
    <div class="layui-form-item" style="text-align: center">
        <a class="layui-btn" lay-filter="updateLink" lay-submit>提交</a>
    </div>
</form>
<script type="text/javascript" src="${path}/static/layui/layui.js"></script>
<script type="text/javascript">
    var path = "${path}";
</script>

<script>
    var path = "${path}";
    layui.use(['form', 'layer', 'laydate', 'table', 'upload', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            upload = layui.upload,
            table = layui.table;

        form.on("submit(updateLink)", function (data) {
            //console.log(data.field);
            var loginLoadIndex = layer.load(2);
            var ajaxReturnData;
            $.ajax({
                type: 'post',
                url: path + '/article/save.do',
                dataType: 'html',
                data: data.field,
                // contentType: 'application/json',
                success: function (data) {
                    layer.close(loginLoadIndex);
                    ajaxReturnData = JSON.parse(data);
                    if (ajaxReturnData.code == '0') {
                        layer.msg('保存成功', {icon: 1});
                        setTimeout(function (){
                            var i = layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            layer.close(i);
                            // 刷新父页面
                            parent.location.reload();
                        }, 1500);
                    } else {
                        layer.msg(ajaxReturnData.msg, {icon: 5});
                        return false;
                    }
                },
                error: function () {
                    layer.close(loginLoadIndex);
                    layer.msg("请求失败,请重试", {icon: 5});
                    return false;
                }
            });
        });
    })

</script>
</body>
</html>


